home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Applications / QuArK / plugins / mb2caulk.py < prev    next >
Text File  |  2004-01-05  |  5KB  |  154 lines

  1. """   QuArK  -  Quake Army Knife Bezier shape makers
  2.  
  3. """
  4.  
  5. # THIS FILE IS PROTECTED BY THE GNU GENERAL PUBLIC LICENCE
  6. # FOUND IN FILE "COPYING.TXT"
  7.  
  8. ########################################################
  9. #
  10. #                          Caulk Plugin
  11. #                          v1.0, Aug 2000
  12. #                      works with Quark 6.0b2
  13. #
  14. #
  15. #                    by tiglari@hexenworld.net
  16. #
  17. #   You may freely distribute modified & extended versions of
  18. #   this plugin as long as you give due credit to tiglari &
  19. #   Armin Rigo. (It's free software, just like Quark itself.)
  20. #
  21. #   Please notify bugs & improvements to tiglari@hexenworld.com
  22. #
  23. ###
  24. ##########################################################
  25.  
  26. #$Header: /cvsroot/quark/runtime/plugins/mb2caulk.py,v 1.3 2001/03/01 19:13:54 decker_dk Exp $
  27.  
  28. Info = {
  29.    "plug-in":       "Caulk shader plugin",
  30.    "desc":          "Pasting caulk shader on stuff",
  31.    "date":          "20 Aug 2000",
  32.    "author":        "tiglari",
  33.    "author e-mail": "tiglari@hexenworld.com",
  34.    "quark":         "Version 6.0b2" 
  35. }
  36.  
  37.  
  38. import quarkx
  39. import quarkpy.mapmenus
  40. from quarkpy.maputils import *
  41.  
  42. from quarkpy.b2utils import *
  43. from tagging import *
  44.  
  45. def gettaggedcorners(editor):
  46.     face = gettaggedface(editor)
  47.     if face is not None:
  48.         vtxes = face.vertices
  49.         if len(vtxes)==1:  # don't do this with shared faces
  50.             return vtxes[0]
  51.     b2cp = gettaggedb2cp(editor)
  52.     if b2cp is not None:
  53.         cp = b2cp.b2.cp
  54.         m, n = len(cp)-1, len(cp[0])-1
  55.         #
  56.         # clockwise traversal
  57.         #
  58.         return cp[0][0], cp[0][n], cp[m][n], cp[m][0]
  59.     return None
  60.  
  61.  
  62. def cleanpoly(poly):
  63.     used = poly.faces
  64.     for face in poly.subitems[:]:
  65.         if not face in used:
  66.             poly.removeitem(face)
  67.  
  68.  
  69. #
  70. # project outline (a vertex-cycle) onto face of poly
  71. # if there's no impingement, return None.
  72. # otherwise return a poly or group, suitablefor replacing
  73. # original poly
  74. #
  75. def projectOutlineTex(face,poly,outline,tex):
  76.     "returns None, if outline doesn't project onto face of poly"
  77.     "a poly with texture replaced, or a group where member has replement"
  78.     undo = quarkx.action()
  79.     core = poly.copy()    # the `central' piece that will get the tex
  80.     periphery = []    # the surrounding pieces that don't
  81.     for i in range(len(outline)):
  82.         #
  83.         # kewl Python feature: when index=-1, last element of
  84.         #    list is picked
  85.         #
  86.         p0, p1 = outline[i-1], outline[i]
  87.         edge = quarkx.vect((p0-p1).xyz)
  88.         normal,dist = face.normal, face.dist
  89.         p3 = projectpointtoplane(p0,normal,dist*normal,normal)
  90.         cutter = face.copy()
  91.         cutter.distortion(edge^normal,p3)
  92.         offcut = core.copy()
  93.         cutter2 = cutter.copy()
  94.         cutter2.swapsides()
  95.         offcut.appenditem(cutter)
  96.         if not offcut.broken:
  97.             cleanpoly(offcut)
  98.             core.appenditem(cutter2)
  99.             periphery.append(offcut)
  100.     cleanpoly(core)
  101.     for aface in core.faces:
  102.        if not (aface.normal-normal):
  103.            aface["tex"]=tex
  104.            break
  105.     if periphery:
  106.         result=quarkx.newobj(poly.shortname+'_group:g')
  107.         result.appenditem(core)
  108.         for item in periphery:
  109.             result.appenditem(item)
  110.         return result
  111.     return core
  112.  
  113.  
  114.  
  115. def tagmenu(o, editor, oldfacemenu = quarkpy.mapentities.FaceType.menu.im_func):
  116.     "the new right-mouse for sides"
  117.     menu = oldfacemenu(o, editor)
  118.     tagpop = findlabelled(menu, 'tagpop')
  119.     corners = gettaggedcorners(editor)
  120.  
  121.     def nodrawclick(m,face=o,editor=editor,corners=corners):
  122.         faces = face.faceof
  123.         if faces[0].type==":f":  # unused face
  124.             return
  125.         if len(faces)>1:
  126.             quarkx.msgbox("Sorry, doing this to shared faces is too hard for me today",
  127.               MT_INFORMATION, MB_OK)
  128.             return
  129.         poly = faces[0]
  130.         #
  131.         # FIXME: get the name of the caulk texture out of
  132.         #   the game config files.
  133.         #
  134.         new = projectOutlineTex(face, poly, corners, 'common/caulk')
  135.         if new is not None:
  136.             undo = quarkx.action()
  137.             undo.exchange(poly, new)
  138.             editor.ok(undo, "caulk from tagged")
  139.  
  140.     nodraw = qmenu.item("Caulk from tagged",nodrawclick)
  141.     if corners is None:
  142.         nodraw.state=qmenu.disabled
  143.     tagpop.items.append(nodraw)
  144.     return menu
  145.  
  146. quarkpy.mapentities.FaceType.menu = tagmenu
  147.  
  148.  
  149. # ----------- REVISION HISTORY ------------
  150. #$Log: mb2caulk.py,v $
  151. #Revision 1.3  2001/03/01 19:13:54  decker_dk
  152. #Corrected CVS log and header tags.
  153. #
  154. #